$(function () {
    //从url中获取要查询的员工id
    var employId = getQueryString('id');
    var showUrl = '/employ/showEmploy?employId='+employId;
    var updateUrl = '/employ/updateEmploy';
    //显示员工信息
    initEmploy();


    $('#updateEmploy').click(function () {
        var format = new FormData();
        var employ = {};
        employ.id = employId;
        employ.employName = $('#employName').val();
        employ.idCard = $('#idCard').val();
        employ.phone = $('#phone').val();
        employ.mail = $('#mail').val();
        employ.gender = $('#gender').val();
        employ.salary = $('#salary').val();
        employ.role = $("#role").val();
        employ.status = $('#status').val();
        employ.entryTime = $('#entryTime').val();
        format.append('employStr',JSON.stringify(employ));
        $.ajax({
            url:updateUrl,
            type:"POST",
            data:format,
            contentType:false,
            processData:false,
            cache:false,
            success:function (data){
                alert(data.message);
                if (data.code==200){
                    //添加成功
                }
            }
        })

    });

    function initEmploy() {
        $.getJSON(showUrl,function (data) {
            if (data.code == 200) {
                $('#employName').val(data.data.employName);
                $('#idCard').val(data.data.idCard);
                $('#phone').val(data.data.phone);
                $('#mail').val(data.data.mail);
                $('#gender').val(data.data.gender);
                $('#salary').val(data.data.salary);
                $("#role option[value="+data.data.role+"]").attr("selected","selected");
                $("#status option[value="+data.data.status+"]").attr("selected","selected");
                $('#entryTime').val(new Date(data.data.entryTime).Format("yyyy-MM-dd"));
            }
        })
    }
});